import 'package:app/common/index.dart';
import 'package:app/router/index.dart';
import 'package:app/store/index.dart';
import 'package:app/theme/app_theme.dart';
import 'package:app/widgets/message.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import "package:provider/provider.dart";

void main() {
  Global.init().then((_) => runApp(MyApp()));
}

class MyApp extends StatelessWidget {
  MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => UserModel()),
        ChangeNotifierProvider(create: (_) => ThemeModel())
      ],
      child: Consumer<ThemeModel>(builder: (context, model, child) {
        return MaterialApp.router(
          localizationsDelegates: GlobalMaterialLocalizations.delegates,
          supportedLocales: const [
            Locale('en', ''),
            Locale('zh', ''),
            Locale('ru', ''),
            Locale('es', ''),
            Locale('hi', ''),
          ],
          locale: const Locale('zh', ''), // 指定当前APP的语言环境，以上都是配置项，不可或缺
          themeMode: model.themeMode,
          theme: AppTheme.lightTheme(context),
          darkTheme: AppTheme.darkTheme(context),
          routerConfig: router,
          builder: EasyLoading.init(),
        );
      }),
    );
  }
}
